package com.zzw.zim.system.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzw.zim.system.dto.AddSysMenuDTO;
import com.zzw.zim.system.dto.EditSysMenuDTO;
import com.zzw.zim.system.dto.QueryMenuPageDTO;
import com.zzw.zim.system.entitys.SysMenuEntity;
import com.zzw.zim.system.dao.SysMenuDao;
import com.zzw.zim.system.service.SysMenuService;
import com.zzw.zim.system.vo.SysMenuVo;
import org.springframework.stereotype.Service;
import java.util.UUID;

@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuDao, SysMenuEntity> implements SysMenuService {


    @Override
    public String savaMenu(AddSysMenuDTO dto) {
        SysMenuEntity entity = new SysMenuEntity();
        BeanUtil.copyProperties(dto,entity);
        entity.setId(UUID.randomUUID().toString().replace("-",""));
        baseMapper.insert(entity);
        return String.format("新增菜单成功，菜单名称：%s",entity.getName());
    }

    @Override
    public String editMenu(EditSysMenuDTO dto) {
        SysMenuEntity entity = new SysMenuEntity();
        BeanUtil.copyProperties(dto,entity);
        return baseMapper.updateById(entity)==1?"更新成功":"更新失败";
    }

    @Override
    public Page<SysMenuVo> queryMenuPage(QueryMenuPageDTO dto) {
        Page<SysMenuVo> page = new Page<>(dto.getPage(), dto.getSize());
        page=baseMapper.selectByPage(page,dto);
        return page;
    }

    @Override
    public SysMenuVo queryInfo(String id) {
        SysMenuEntity entity = baseMapper.selectById(id);
        SysMenuVo vo = new SysMenuVo();
        BeanUtil.copyProperties(entity,vo);
        return vo;
    }
}
